home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
101-125
/
118
/
empire
/
src
/
source.zoo
/
startup.d
< prev
next >
Wrap
Text File
|
1987-12-02
|
11KB
|
489 lines
#include:exec/tasks.g
#include:util.g
#include:libraries/dos.g
#empire.g
#empfunc.g
Handle_t Stdout;
uint Seed;
/*
* gotControlC - return 'true' if the user has typed a control-C.
*/
proc gotControlC()bool:
if
if UsingSerial then
serialGotControlC()
else
SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C ~= 0
fi
then
writeln(PromptOut;);
writeln(PromptOut; "Interrupt!!!");
true
else
false
fi
corp;
/*
* pause - delay for the given number of tenths of a second.
*/
proc pause(uint time)void:
if time ~= 0 then
Delay(time * 5);
fi;
corp;
/*
* writeChar - do an unbuffered write of the single character to the output.
*/
proc writeChar(char ch)void:
if UsingSerial then
serialPutChar(ch);
else
pretend(Write(Stdout, pretend(&ch, *byte), 1), void);
fi;
corp;
/*
* writeString - write an entire string immediately.
*/
proc writeString(*char st)void:
while st* ~= '\e' do
writeChar(st*);
st := st + sizeof(char);
od;
corp;
/*
* getPassword - prompt for and check the current user's password.
*/
proc getPassword(*char prompt, existingPassword)bool:
[PASSWORD_LEN] char password;
uint j;
char CSI = '\(0x9b)';
bool ok;
write(Chout; prompt);
if UsingSerial then
serialEcho(false);
else
write("\(CSI)30;40m");
fi;
ok := readLine(&password[0], PASSWORD_LEN);
if UsingSerial then
serialEcho(true);
else
write("\(CSI)31;40m");
fi;
if not ok then
pretend(ioerror(Chin), void);
false
elif CharsEqual(&password[0], existingPassword) then
true
else
write(Chout; "Password incorrect. ");
false
fi
corp;
/*
* printFile - print a file (if it exists).
*/
proc printFile(*char fileName)void:
channel input text tempChan;
file() tempFile;
if open(tempChan, tempFile, fileName) then
while readln(tempChan; &InputBuffer[0]) do
writeln(Chout; &InputBuffer[0]);
od;
close(tempChan);
fi;
corp;
/*
* getVerifiedPassword - get a new password for the country. Verify it.
* return 'true' if it is verified, else 'false'. If we get it, install
* into the user structure.
*/
proc getVerifiedPassword(*char prompt)bool:
char CSI = '\(0x9b)';
[PASSWORD_LEN] char password, verifyPassword;
bool aborting;
write(Chout; "Enter new password: ");
if UsingSerial then
serialEcho(false);
else
write("\(CSI)30;40m");
fi;
aborting := not readLine(&password[0], PASSWORD_LEN);
if UsingSerial then
serialEcho(true);
else
write("\(CSI)31;40m");
fi;
if not aborting then
write(Chout; "Re-enter password to verify: ");
if UsingSerial then
serialEcho(false);
else
write("\(CSI)30;40m");
fi;
aborting := not readLine(&verifyPassword[0], PASSWORD_LEN);
if UsingSerial then
serialEcho(true);
else
write("\(CSI)31;40m");
fi;
if not aborting and CharsEqual(&password[0], &verifyPassword[0]) then
ThisCountry*.c_password := password;
true
else
writeln(Chout; "Password not verified.");
false
fi
else
false
fi
corp;
/*
* putPrompt - print a prompt to the local system owner.
*/
proc putPrompt()void:
pretend(Write(Stdout, pretend("E > ", *byte), 4), void);
corp;
/*
* playGame - play a session of the game. Return 'true' if have output a
* message line to the console during a serial connection.
*/
proc playGame()bool:
[NAME_LEN] char name;
[25] char buf;
uint i, j, k;
bool aborting, dirty;
dirty := false;
writeln(Chout; " Welcome to Amiga Empire Version 1.0!!");
writeln(Chout; " by Chris Gray");
writeln(Chout;);
writeln(Chout;);
printFile(CONNECT_MESSAGE_FILE);
openFile();
readWorld();
write(Chout; "Enter country name: ");
aborting := not readLine(&name[0], NAME_LEN);
if not aborting then
j := 0;
while name[j] = ' ' do
j := j + 1;
od;
aborting := name[j] = '\e';
fi;
if not aborting then
i := 0;
while i ~= World.w_currCountries and
not CharsEqual(&name[j], &Country[i].c_name[0]) do
i := i + 1;
od;
if i = World.w_currCountries then
writeln(Chout; "Country ", &name[j], " does not exist.");
if World.w_currCountries = World.w_maxCountries then
writeln(Chout; "There is no space for more countries.");
aborting := true;
elif ask("Do you wish to create it? ") then
if getPassword("Enter creation password for this game: ",
&World.w_password[0]) then
ThisCountryNumber := i;
ThisCountry := &Country[ThisCountryNumber];
if getVerifiedPassword("Enter new password: ") then
k := 0;
while
ThisCountry*.c_name[k] := name[j];
name[j] ~= '\e'
do
k := k + 1;
j := j + 1;
od;
World.w_currCountries := World.w_currCountries + 1;
ThisCountry*.c_status := cs_active;
ThisCountry*.c_last := CurrentTime();
pretend(resetTimer(), void);
writeWorld();
else
aborting := true;
fi;
else
writeln(Chout; "Restart to try again.");
aborting := true;
fi;
else
writeln(Chout; "OK.");
aborting := true;
fi;
else
ThisCountryNumber := i;
ThisCountry := &Country[ThisCountryNumber];
if not getPassword("Enter password: ",
&ThisCountry*.c_password[0]) then
writeln(Chout; "Try again.");
if not getPassword("Enter password: ",
&ThisCountry*.c_password[0]) then
writeln(Chout; "Try again.");
if not getPassword("Enter password: ",
&ThisCountry*.c_password[0]) then
writeln(Chout; "Aborting.");
aborting := true;
fi;
fi;
fi;
fi;
if not aborting then
ConvTime(CurrentTime(), &buf[0]);
if UsingSerial then
writeln(&buf[0], " - country ", &name[0], " logged in.");
putPrompt();
fi;
writeln(LogChannel; &buf[0], " - country ", &name[0],
" logged in.");
ConvTime(ThisCountry*.c_last, &buf[0]);
writeln(Chout; &name[0], " last on at ", &buf[0]);
if resetTimer() then
write(Chout; "Sorry, you are out of time for today.");
writeln(Chout; " Come back tomorrow.");
else
printFile(LOGIN_MESSAGE_FILE);
processCommands();
World.w_lastRun := CurrentTime();
writeWorld();
fi;
ConvTime(CurrentTime(), &buf[0]);
writeln(LogChannel; &buf[0], " - country ",
&ThisCountry*.c_name[0], " logged out.");
if UsingSerial then
writeln();
writeln(&buf[0], " - country ",
&ThisCountry*.c_name[0], " logged out.");
dirty := true;
fi;
fi;
fi;
closeFile();
close(LogChannel);
if not open(LogChannel, LogFile, LOG_FILE) then
writeln("Can't reopen ", LOG_FILE, " for output.");
exit(1);
fi;
if not TextAppend(LogChannel) then
writeln("Can't reappend to ", LOG_FILE, '.');
close(LogChannel);
exit(1);
fi;
dirty
corp;
/*
* shout - shout an important warning on the console.
*/
proc shout(*char message)void:
char CSI = '\(0x9b)';
uint i;
writeln("\(CSI)30;41m ", /* why is the extra space needed? */
" "
" ");
writeln(
" "
" ");
writeln(
" "
" ");
write("**** ");
i := 0;
while message* ~= '\e' do
write(message*);
message := message + 1;
i := i + 1;
od;
write("!!! ****");
while i < 63 do
i := i + 1;
write(' ');
od;
writeln();
writeln(
" "
" ");
writeln(
" "
" ");
writeln(
" "
" ",
"\(CSI)31;40m");
corp;
/*
* main - the main program.
*/
proc main()void:
DateStamp_t ds;
*char par;
ulong now;
[80] char buf;
Stdout := Output();
if not IsInteractive(Input()) or not IsInteractive(Stdout) then
writeln("Empire's standard I/O must not be redirected.");
exit(1);
fi;
DateStamp(&ds);
Seed := (ds.ds_Minute >< ds.ds_Tick) | 1;
SerialOpen := false;
if not open(LogChannel, LogFile, LOG_FILE) then
if not FileCreate(LOG_FILE) then
writeln("Can't create ", LOG_FILE);
exit(1);
fi;
if not open(LogChannel, LogFile, LOG_FILE) then
writeln("Can't open ", LOG_FILE, " for output.");
exit(1);
fi;
fi;
if not TextAppend(LogChannel) then
writeln("Can't append to ", LOG_FILE, '.');
close(LogChannel);
exit(1);
fi;
openFile();
readWorld();
closeFile();
now := CurrentTime();
if now < World.w_lastRun then
shout("Current time is earlier than last run time");
elif now > World.w_lastRun + (24 * 60 * 60) then
shout("Current time is more than one day after last run time");
fi;
SectorChar := SECTOR_CHAR;
ShipChar := SHIP_CHAR;
ItemChar := ITEM_CHAR;
par := GetPar();
if par ~= nil then
if not CharsEqual(par, "private") then
writeln("Invalid parameter - only 'private' accepted.");
close(LogChannel);
exit(1);
fi;
open(Chin);
open(Chout);
open(PromptOut);
UsingSerial := false;
pretend(playGame(), void);
else
if not openSerialHandler() then
writeln("Can't open serial port.");
close(LogChannel);
exit(1);
fi;
SerialOpen := true;
LeaveGame := false;
PlayConsole := false;
putPrompt();
while not LeaveGame do
if PlayConsole then
PlayConsole := false;
setDTRoff();
open(Chin);
open(Chout);
open(PromptOut);
UsingSerial := false;
writeln(Chout;);
writeln(Chout;);
pretend(playGame(), void);
setDTRon();
putPrompt();
elif WaitForChar(Input(), 1000000) then
readln(&buf[0]);
if CharsEqual(&buf[0], "QUIT") then
LeaveGame := true;
elif CharsEqual(&buf[0], "play") then
setDTRoff();
open(Chin);
open(Chout);
open(PromptOut);
UsingSerial := false;
writeln(Chout;);
writeln(Chout;);
pretend(playGame(), void);
setDTRon();
putPrompt();
elif buf[0] = '\e' then
putPrompt();
else
writeln("Unknown command - only 'QUIT' and 'play' known.");
putPrompt();
fi;
elif serialActive() then
writeln();
ConvTime(CurrentTime(), &buf[0]);
writeln(&buf[0], " - ", serialSpeed(),
" baud connection established on serial port.");
writeln(LogChannel; &buf[0], " - ", serialSpeed(),
" baud connection established on serial port.");
open(Chin, serialGetChar);
open(Chout, serialPutChar);
open(PromptOut, serialPutChar);
UsingSerial := true;
if not playGame() then
writeln();
fi;
setDTRoff();
ConvTime(CurrentTime(), &buf[0]);
writeln(&buf[0], " - connection terminated on serial port.");
writeln(LogChannel; &buf[0],
" - connection terminated on serial port.");
pause(50);
setDTRon();
putPrompt();
fi;
od;
closeSerialHandler();
fi;
close(LogChannel);
corp;
/*
* random - return a random number 0 - passed range.
*/
proc random(uint rang)uint:
if rang = 0 then
0
else
Seed := Seed * 17137 + 4287;
Seed := (Seed >> 8) >< (Seed << 8);
Seed % rang
fi
corp;